#ifndef PWM_SHOW_H
#define PWM_SHOW_H

#include <QWidget>
#include <QLabel>
#include <QPaintEvent>
#include <QMessageBox>
#include <QPainter>
#include <QPoint>
#include <QPen>
#include <QPushButton>
#include <QFont>
#include <QPoint>
#include <QMouseEvent>
#include <QMainWindow>
#include <QPalette>
#include <QMouseEvent>
#include <QWheelEvent>

class PWM_Show : public QDialog
{
    Q_OBJECT
public:
    explicit PWM_Show(QMainWindow *parent = 0);


    void initShower(long long int * leftPWM,long long int *rightPWM,int Sum)
    {
        this->Sum = Sum;
        this->leftPWM = leftPWM;
        this->rightPWM = rightPWM;
    }
    void setSum(int n)
    {
        this->Sum = n;
    }

    void showtry()
    {
        this->show();
        if (Sum==-1)
        {
            QMessageBox::warning(this,"无数据","请先打开一个文件。","确定");
            this->setVisible(false);
            return;
        }

    }
    void setBasePos(int n)
    {
        this->basePos = n;
    }

private:
    QLabel *noData,*Level[5];
    QLabel *leftPWMLabel,*rightPWMLabel,*sumPWMLabel;
    QLabel *leftPWMNumber,*rightPWMNumber,*sumPWMNumber;
    QPushButton *re,*larger,*smaller;
    QLabel *pwmTrace;
    QPalette *tracePalette;
    QPalette *LabelPalette;
    QLabel *positionLabel[6];

    long long int * leftPWM,*rightPWM,Sum,basePos;
    float zoom;
    inline int min(int a,int b){if (a<b) return a;return b;}
signals:

public slots:
    void Larger()
    {
        if (zoom>=4)
        {
            QMessageBox::warning(this,"错误","已达到最大尺寸","确定");
            return;
        }
        zoom += 0.2;
        this->repaint();
    }
    void Smaller()
    {
        if (zoom <= 0.4)
        {
            QMessageBox::warning(this,"错误","已达到最小尺寸","确定");
            return;
        }
        zoom -= 0.2;
        this->repaint();
    }
protected:
    void paintEvent(QPaintEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event){pwmTrace->setVisible(false);}
    void wheelEvent(QWheelEvent *event);

};

#endif // PWM_SHOW_H
